function initCompanyAndDepartment(){   // 查询所有企业   
		  $.ajax({ 
			  type:"post",
			  url:"selectAllCompanyList",
			  data:{},
			  dataType: 'json',
			  success:function(result){
				if(result.status == "FAILED"){
					layer.msg(result.message);
					return  false;
				}
				var company = JSON.parse(result.company); //企业数据
				for(var i = 0 ;  i < company.data.length; i++){ //初始化企业
					initdepartment (i,result,company.data[i].companyName,company.data[i].no)//初始化部门数据
					if(i == 0){
						$("#enterprise1").val(company.data[0].no + "," + company.data[0].companyName);
						$("#enterprise1").attr("title",company.data[0].companyName);
						continue; //跳出0
					}
					if(i > 0){
						var str =  "<div class='layui-form-item' style='margin-bottom:0'>" +
									   " <label class='layui-form-label'>&nbsp;</label>" +
									   " <div class='layui-input-block'>" +
								  		 "<input type='checkbox' name='enterprise' id='enterprise"+ (i+1) +"' lay-filter='enterprise' value = '"+company.data[i].no +","+ company.data[i].companyName +"' lay-skin='primary' title='"+ company.data[i].companyName+"'>"   +
									   "</div>" +
								    "</div>" ;
						$("#enterprisediv").append(str);
					}
				}
				layui.form.render();
		 	}
		 })
	}
	
function initdepartment (i,result,dataname,datano){//初始化部门
	var Department = JSON.parse(result[datano]); //部门数据
	var departmentdiv = " <div class='layui-form-item' id='"+ datano  +"companydepartment' style='margin-bottom:0 ; display: none;'> " +
				 	      " <label class='layui-form-label bumen' >"+ dataname +"部门</label>  " + 
					 		 "<div class='layui-input-block' id='departmentdiv"+ i+"'> " + 
					  		 "</div>" + 
						" </div>";
	$("#enterprisediv").after(departmentdiv);
	
	for(var x  = 0 ;  x < Department.data.length; x++){
		var department = "<input type='checkbox' name='department' id='department_"+getUUID()+"' value='"+ datano+"-"+ dataname + "," + Department.data[x].no +"-"+Department.data[x].departmentName+"' lay-skin='primary' title='"+ Department.data[x].departmentName +"'>" ;
		$("#departmentdiv" + i).append(department);
	}
}

function getUUID() {
	var s = [];
	var hexDigits = "0123456789abcdef";
	for (var i = 0; i < 36; i++) {
		s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
	}
	s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
	s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
	s[8] = s[13] = s[18] = s[23] = "-";

	var uuid = s.join("");
	return uuid;
}
function initUpdate(id,type){
	 $.ajax({
		 type:"post",
		 url : "updatefindByCarId",
		 data:{id : id ,"type" : type},
		 dataType:"json",
		 success:function(result){
			 for(var i = 0; i < result.length; i++ ){
				 var companydepartmentid = result[i].enterpriseNo + "companydepartment";
				 $("input[name='enterprise'][value='"+result[i].enterpriseNo + "," + result[i].enterpriseName + "']").prop("checked", true);//选中企业
				 
				 if("部门" == type){
					 $("#"+companydepartmentid).show()
					 $("#"+companydepartmentid).children("div").children("input").each(function(){//部门
						 var departmentNo = $(this).val().substring($(this).val().indexOf(",")+1,$(this).val().lastIndexOf('-'));
						 if(result[i].departmentNo == departmentNo ){
							 $(this).prop("checked", true);//选中部门
						 }
						 
					 });
				 }
				 layui.form.render();
			 }
		 }
	 })
}
	
$("#updatebtn_query").on('click',function(){
	layer.open({
		type: 1,
		title: '选择企业以及部门',
		area: ['500px', '680px'],
		btn: ['确定', '取消'],
		content: $('#tan_11'),
		yes:function(index,layero){
			var count = 0;
			var name = null;
			if($("input[name='enterprise']:checked").length == 0){
				layer.msg("请选择企业");
				return false;
			}
			$("input[name='enterprise']:checked").each(function(){//获取企业下所有部门
				var id = $(this).val().substring(0,$(this).val().indexOf(","));
				count = $("#"+id+"companydepartment").find($("input[name='department'][id^='department']:checked")).length > 0 ? false : true;
				name = $(this).attr("title");
				if(count){ //效验部门
					layer.msg("请选择 "+name+" 下的部门");
					return false;
				}
			})
			
			if(count){
				return false;
			}
			
			if($("input[name='department'][id^='department']:checked").length == 0 ){			
				layer.msg("请选择部门");
				return false;
			}
			layer.close(index); 				
		},
		btn2: function(index, layero){//点击取消按钮刷新页面 
		}
	});
})	
	
$("#updatebtn_query1").on('click',function(){
	layer.open({
		type: 1,
		title: '选择企业以及部门',
		area: ['500px', '680px'],
		btn: ['确定', '取消'],
		content: $('#tan_11'),
		yes:function(index,layero){
			var count = 0;
			var name = null;
			if($("input[name='enterprise']:checked").length == 0){
				layer.msg("请选择企业");
				return false;
			}
			layer.close(index); 				
		},
		btn2: function(index, layero){//点击取消按钮刷新页面 
		}
	});
})
	
/***************************层级菜单js**********************************/
	
	
	$("#peccancy").on('click',function(){
		var obj = $("input[type='checkbox'][name='carId']:checked");
		if(obj.length > 1){
			layer.msg("每次只能选择一车辆！");
			return false;
		}
		if(obj.length == 0){
			layer.msg("请选择车辆！");
			return false;
		}
		win_href(obj.val(),"6")
	})
	$("#barbarism").on('click',function(){
		var obj = $("input[type='checkbox'][name='carId']:checked");
		if(obj.length > 1){
			layer.msg("每次只能选择一车辆！");
			return false;
		}
		if(obj.length == 0){
			layer.msg("请选择车辆！");
			return false;
		}
		win_href(obj.val(),"5")
	})
	$("#safe").on('click',function(){
		var obj = $("input[type='checkbox'][name='carId']:checked");
		if(obj.length > 1){
			layer.msg("每次只能选择一车辆！");
			return false;
		}
		if(obj.length == 0){
			layer.msg("请选择车辆！");
			return false;
		}
		win_href(obj.val(),"4")
	})
	$("#maintenance").on('click',function(){
		var obj = $("input[type='checkbox'][name='carId']:checked");
		if(obj.length > 1){
			layer.msg("每次只能选择一车辆！");
			return false;
		}
		if(obj.length == 0){
			layer.msg("请选择车辆！");
			return false;
		}
		win_href(obj.val(),"1")
	})
	$("#track").on('click',function(){
		var obj = $("input[type='checkbox'][name='carId']:checked");
		if(obj.length > 1){
			layer.msg("每次只能选择一车辆！");
			return false;
		}
		if(obj.length == 0){
			layer.msg("请选择车辆！");
			return false;
		}
		win_href(obj.val(),"3")
	})
	$("#worktrack").on('click',function(){
		var obj = $("input[type='checkbox'][name='carId']:checked");
		if(obj.length > 1){
			layer.msg("每次只能选择一车辆！");
			return false;
		}
		if(obj.length == 0){
			layer.msg("请选择车辆！");
			return false;
		}
		win_href(obj.val(),"10")
	})
	$("#Prepare").on('click',function(){
		var obj = $("input[type='checkbox'][name='carId']:checked");
		if(obj.length > 1){
			layer.msg("每次只能选择一车辆！");
			return false;
		}
		if(obj.length == 0){
			layer.msg("请选择车辆！");
			return false;
		}
		win_href(obj.val(),"2")
	})
	
	$("#carinfo").on('click',function(){
		var obj = $("input[type='checkbox'][name='carId']:checked");
		if(obj.length > 1){
			layer.msg("每次只能选择一车辆！");
			return false;
		}
		if(obj.length == 0){
			layer.msg("请选择车辆！");
			return false;
		}
		win_href(obj.val(),"")
	})
	$("#maintain").on('click',function(){
		var obj = $("input[type='checkbox'][name='carId']:checked");
		if(obj.length > 1){
			layer.msg("每次只能选择一车辆！");
			return false;
		}
		if(obj.length == 0){
			layer.msg("请选择车辆！");
			return false;
		}
		win_href(obj.val(),"7")
	})
	$("#repair").on('click',function(){
		var obj = $("input[type='checkbox'][name='carId']:checked");
		if(obj.length > 1){
			layer.msg("每次只能选择一车辆！");
			return false;
		}
		if(obj.length == 0){
			layer.msg("请选择车辆！");
			return false;
		}
		win_href(obj.val(),"8")
	})
	$("#accident").on('click',function(){
		var obj = $("input[type='checkbox'][name='carId']:checked");
		if(obj.length > 1){
			layer.msg("每次只能选择一车辆！");
			return false;
		}
		if(obj.length == 0){
			layer.msg("请选择车辆！");
			return false;
		}
		win_href(obj.val(),"9")
	})
	
	function win_href(carid,type){
		window.location.href="checkDetails?carId="+carid+"&tag="+type;
	}
	
	$(document).ready(function() {
		$("#add_sel").click(function() {
			$(".xl").toggle();
			$(".xl_1").hide();
			$(".xl_2").hide();
			$(".xl_3").hide();
		});
		$("#add_sel_2").click(function() {
			$(".xl_2").toggle();
			$(".xl").hide();
			$(".xl_1").hide();
			$(".xl_3").hide();
		});
		$("#add_sel_3").click(function() {
			$(".xl_3").toggle();
			$(".xl_2").hide();
			$(".xl").hide();
			$(".xl_1").hide()
		});
		$("#add_sel_1").click(function() {
			$(".xl_1").toggle();
			$(".xl_2").hide();
			$(".xl").hide();
			$(".xl_3").hide();
		});
	});
	
	
/****************************************获取保险信息*******************************************/	
	
function insuranceInfo(compulsory,business){   // 所有保险信息
	  $.ajax({ 
		  type:"post",
		  url:"selectInsuranceInfo",
		  data:{},
		  dataType: 'json',
		  success:function(result){
			  var cparam = "<option value=''></option>";
			  var bparam = "<option value=''></option>";
			  for(var i = 0 ; i < result.compulsory.length ; i++ ){
				  if(compulsory == result.compulsory[i].name){
					  cparam += "<option value='"+result.compulsory[i].id+"' selected ='selected' >"+result.compulsory[i].name+"</option>";
					  continue;
				  }
				  cparam += "<option value='"+result.compulsory[i].id+"'>"+result.compulsory[i].name+"</option>";
			  }
			  $("#cinsuranceid").append(cparam)//强制险
			  $("#upcinsuranceid").append(cparam)
			  for(var i = 0 ; i < result.business.length ; i++ ){
				  if(business == result.business[i].name){
					  bparam += "<option value='"+result.business[i].id+"'  selected ='selected'>"+result.compulsory[i].name+"</option>";
					  continue;
				  }
				  bparam += "<option value='"+result.business[i].id+"'>"+result.business[i].name+"</option>";
			  }
			  $("#binsuranceid").append(bparam)//商业险
			  $("#upbinsuranceid").append(bparam);
			layui.form.render();
	 	}
	 })
}

	
	
	